/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DataAccess;

import Entity.EAccount;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;

/**
 *
 * @author Home
 */
public class Report {

    public static boolean insertReport(Entity.Report report) {
        try {
            String sql = "insert into Report(fromSales, ToManager, Title, [Content]) values(?, ?, ?, ?)";
            PreparedStatement pst = DBUtil.getConnection(DBUtil.getInfoDB()).prepareCall(sql);
            pst.setInt(1, report.getFromSales());
            pst.setInt(2, report.getToManager());
            pst.setString(3, report.getTile());
            pst.setString(4, report.getContent());
            int i = pst.executeUpdate();
            if (i != 0) {
                return true;
            } else {
                return false;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return true;
    }

    public static boolean updateReport(int idReport) {
        try {
            String sql = "update Report set status=1 where ReportID=?";
            PreparedStatement pst = DBUtil.getConnection(DBUtil.getInfoDB()).prepareCall(sql);
            pst.setInt(1, idReport);
            int i = pst.executeUpdate();
            if (i != 0) {
                return true;
            } else {
                return false;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return true;
    }

    public static boolean getAllAccount(int toMan) {
        boolean bfo = false;
        try {
            Entity.EAccount eaccount = new EAccount();
            String sql = "select * from Account where Active=1 AND AccountID=" + toMan;
            Statement st = DBUtil.getConnection(DBUtil.getInfoDB()).createStatement();
            ResultSet rs = st.executeQuery(sql);
            while (rs.next()) {

                eaccount.setAcountID(rs.getInt("AccountID"));
                bfo = true;
            }
            System.out.println(eaccount.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return bfo;
    }
}
